package o;

import com.huawei.hmf.annotation.ActivityDefine;
import com.huawei.hmf.annotation.ApiDefine;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.hmf.annotation.Singleton;
import java.util.HashMap;
import java.util.Map;

public class fhu {
    private Map<Class<?>, fhw> ˏ;
    private Map<String, fhw> ॱ;

    public static class b {
        fhw ˊ;
        Map<String, fhw> ˋ;
        Map<Class<?>, fhw> ˎ;
        boolean ॱ;

        public fhw ˊ(Class<?> cls) {
            if (((ApiDefine) cls.getAnnotation(ApiDefine.class)) != null) {
                boolean z;
                fhw o_fhw = new fhw(cls);
                if (cls.getAnnotation(Singleton.class) != null) {
                    z = true;
                } else {
                    z = false;
                }
                o_fhw.ˎ(z);
                return o_fhw;
            }
            ActivityDefine activityDefine = (ActivityDefine) cls.getAnnotation(ActivityDefine.class);
            if (activityDefine != null) {
                return new fiz(cls, activityDefine.protocol(), activityDefine.result());
            }
            FragmentDefine fragmentDefine = (FragmentDefine) cls.getAnnotation(FragmentDefine.class);
            if (fragmentDefine != null) {
                return new fiz(cls, fragmentDefine.protocol(), null);
            }
            return null;
        }

        private b() {
            this.ˎ = new HashMap();
            this.ˋ = new HashMap();
            this.ˊ = null;
        }

        public b ˏ(Class<?> cls, String str) {
            ˋ(cls);
            if (this.ॱ && this.ˊ != null) {
                this.ˊ.ˊ(str);
            }
            return this;
        }

        public b ˋ(Class<?> cls) {
            boolean z = false;
            this.ॱ = false;
            if (cls.isInterface()) {
                throw new IllegalArgumentException(cls.getName() + " can not be interface");
            }
            ApiDefine apiDefine = (ApiDefine) cls.getAnnotation(ApiDefine.class);
            if (apiDefine != null) {
                if (cls.getAnnotation(Singleton.class) != null) {
                    z = true;
                }
                ˋ(apiDefine.uri(), apiDefine.alias(), cls, z);
            } else {
                ActivityDefine activityDefine = (ActivityDefine) cls.getAnnotation(ActivityDefine.class);
                if (activityDefine != null) {
                    ˊ(activityDefine.alias(), cls, activityDefine.protocol(), activityDefine.result());
                } else {
                    FragmentDefine fragmentDefine = (FragmentDefine) cls.getAnnotation(FragmentDefine.class);
                    if (fragmentDefine != null) {
                        ˊ(fragmentDefine.alias(), cls, fragmentDefine.protocol(), null);
                    } else {
                        throw new IllegalArgumentException(cls.getName() + " annotation is not present");
                    }
                }
            }
            return this;
        }

        public b ˋ(Class<?> cls, String str, Class<?> cls2, boolean z) {
            this.ॱ = false;
            this.ˊ = new fhw(cls2);
            this.ˊ.ˎ(z);
            if (str == null || str.length() == 0) {
                this.ˎ.put(cls, this.ˊ);
            } else {
                this.ˋ.put(fhu.ˋ(str, cls), this.ˊ);
            }
            this.ॱ = true;
            return this;
        }

        public b ˊ(String str, Class<?> cls, boolean z) {
            this.ॱ = false;
            if (str.length() > 0) {
                this.ˊ = new fhw(cls);
                this.ˊ.ˎ(z);
                this.ˋ.put(str, this.ˊ);
                this.ॱ = true;
            }
            return this;
        }

        public b ˊ(String str, Class<?> cls, Class<?> cls2, Class<?> cls3) {
            this.ॱ = false;
            if (str.length() > 0) {
                this.ˊ = new fiz(cls, cls2, cls3);
                this.ˋ.put(str, this.ˊ);
                this.ॱ = true;
                return this;
            }
            throw new IllegalArgumentException(cls.getName() + ": `alias` can not be empty");
        }

        public fhu ˊ() {
            return new fhu();
        }
    }

    public static b ˎ() {
        return new b();
    }

    private fhu(b bVar) {
        this.ˏ = bVar.ˎ;
        this.ॱ = bVar.ˋ;
    }

    private static String ˋ(String str, Class cls) {
        return str + "/" + cls.getName();
    }

    public fhw ˏ(Class cls) {
        return (fhw) this.ˏ.get(cls);
    }

    public fhw ॱ(String str) {
        return (fhw) this.ॱ.get(str);
    }

    public fhw ॱ(String str, Class cls) {
        return ॱ(ˋ(str, cls));
    }
}
